package com.tanqing.ddd.domain.policy;

import com.tanqing.ddd.domain.domain.DomainEvent;
import com.tanqing.ddd.domain.domain.DomainEventListener;
import com.tanqing.ddd.domain.event.CheckInFailEvent;
import com.tanqing.ddd.domain.event.CheckoutFailEvent;
import com.tanqing.ddd.domain.service.AlarmService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

@Component
public class AlarmPolicy implements DomainEventListener {

    @Resource
    private AlarmService alarmService;

    @Override
    public void onEvent(DomainEvent event) {
        if (event instanceof CheckInFailEvent) {
            CheckInFailEvent checkInFailEvent = (CheckInFailEvent) event;
            alarmService.alerm(checkInFailEvent.getPlate(), checkInFailEvent.getMsg());
        }

        if (event instanceof CheckoutFailEvent) {
            CheckoutFailEvent checkoutFailEvent = (CheckoutFailEvent) event;
            alarmService.alerm(checkoutFailEvent.getPlate(), checkoutFailEvent.getMsg());
        }
    }
}
